clear all
set more off

local out2="\outregsQJE\"
cd "\workfiles"

use step001_QJE_2, clear

tsset firm_id time

*** define treatment as given inflation TIMES treatment status
gen Treat=treatment_old*infl

*** define variables in such a way that it's easier to interpret
*** positive values: higher/better
*** zero values: no change
*** negative values: lower/worse

gen sitgenR=sitgen-2

gen promigR=0 if promig==1
replace promigR=12.5 if promig==2
replace promigR=37.5 if promig==3
replace promigR=62.5 if promig==4
replace promigR=88.5 if promig==5
replace promigR=100  if promig==6

gen sitimp5R=sitimp5-3

gen pretotR=pretot-2

gen liquidR=liquid-2

gen occtotR=occtot-2

gen invpreR=invpre-3

gen sitcreR=sitcre-2

winsor dprez, p(0.02) gen(dprez_w)

local controls0=""	

***======================================================================   
*** 		construct measures of uncertainty   
***======================================================================   

*** 3-month ahead: mean and std
gen mean3m=( (-1)*sitm3m + 0*situ3m + 1*sitp3m )/100
gen uncertainty3m=( (-1-mean3m)^2*sitm3m + (0-mean3m)^2*situ3m + (1-mean3m)^2*sitp3m )/100
replace uncertainty3m=uncertainty3m^0.5

*** 3-year ahead: mean and std
gen mean3a=( (-1)*sitm3a + 0*situ3a + 1*sitp3a )/100
gen uncertainty3a=( (-1-mean3a)^2*sitm3a + (0-mean3a)^2*situ3a + (1-mean3a)^2*sitp3a )/100
replace uncertainty3a=uncertainty3a^0.5

*** restrict the sample only to the period with treatment and control groups
keep if time>=208

***======================================================
*** 	formatted output 	
***======================================================

tempname tempfile0 
postfile `tempfile0' ///
		str100 variable_name 	///												
		str12 v_coef_se				///
		str12 v_R2 ///
		str12 v_F1 ///
		str12 v_N ///
		using `out2'Table06_format.dta, replace every(1)

	
***======================================================
*** 	responses in T+1 to a treatment in T-1
***======================================================

*** MACRO: general economic conditions in Italy (next three months)
ivreghdfe sitgenR `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	ffirst dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", replace dec(3) ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MACRO: general economic conditions in Italy (next three months)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	
	

***	MACRO: general economic conditions in Italy: probability of 
***        improvement (next three months)
ivreghdfe promigR `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3)  ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MACRO: general economic conditions in Italy: probability of improvement (next three months)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	

***	MICRO: business conditions for your company (next three months)
ivreghdfe sitimp5R `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3)  ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: business conditions for your company (next three months)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	

***	MICRO: total demand for your company (next three months)
ivreghdfe pretotR `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3)  ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: total demand for your company (next three months)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	

***	MICRO: acces to credit (next three months)
ivreghdfe liquidR `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3)  ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: acces to credit (next three months)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	

***	MICRO: access conditions to credit (wrt past 3 months)
ivreghdfe sitcreR `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)	
outreg2 using "`out2'Table06.dta", append dec(3) ///
	addstat("1st stage F stat", e(widstat))		

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: access conditions to credit (wrt past 3 months)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	

***	MICRO: uncertainty (next three months)
ivreghdfe uncertainty3m `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)	
outreg2 using "`out2'Table06.dta", append  dec(3) ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: uncertainty (next three months)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	
	
***	MICRO: uncertainty (next three years)
ivreghdfe uncertainty3a `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)	
outreg2 using "`out2'Table06.dta", append  dec(3) ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: uncertainty (next three years)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	
	
	
***	MICRO: employment change (next three months)
ivreghdfe occtotR `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3)  ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: employment change (next three months)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	
	
	
***	MICRO: investment plan for the next calendar year
ivreghdfe invpreR `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)	
outreg2 using "`out2'Table06.dta", append dec(3) ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: investment plan for the next calendar year") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	
	

*** MICRO: Dprez: For the next 12 months. what do you expect will be the average change in your firm’s prices?
ivreghdfe dprez_w `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	ffirst dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3) ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: Dprez: For the next 12 months. what do you expect will be the average change in your firm’s prices?") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	


***	MICRO: Please indicate direction and intensity of the following FACTORS as they will affect your firm’s selling prices in the next 12 months: (scale from -3 to 3)
*** Dpr: TOTAL DEMAND
ivreghdfe dpr `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3)  ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("MICRO: Please indicate direction and intensity of the following FACTORS as they will affect your firm’s selling prices in the next 12 months: (scale from -3 to 3)") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	

*** MICRO: Please indicate direction and intensity of the following FACTORS as they will affect your firm’s selling prices in the next 12 months: (scale from -3 to 3)
*** Mppr: RAW MATERIALS PRICES
ivreghdfe mppr `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3)  ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("Please indicate direction and intensity of the following FACTORS as they will affect your firm’s selling prices in the next 12 months: (scale from -3 to 3): RAW MATERIALS PRICES") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	

***	MICRO: Please indicate direction and intensity of the following FACTORS as they will affect your firm’s selling prices in the next 12 months: (scale from -3 to 3)
*** Clpr: LABOUR COSTS
ivreghdfe clpr `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3)  ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("Please indicate direction and intensity of the following FACTORS as they will affect your firm’s selling prices in the next 12 months: (scale from -3 to 3): LABOUR COSTS") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	

***	MICRO: Please indicate direction and intensity of the following FACTORS as they will affect your firm’s selling prices in the next 12 months: (scale from -3 to 3)
*** Prpr: PRICING POLICIES of your firm’s main competitors
ivreghdfe prpr `controls0' ///
	(l.it12_all = l.Treat) [aw=peso], ///
	dkraay(2) absorb(i.setton5#i.trimestre)
outreg2 using "`out2'Table06.dta", append dec(3)  ///
	addstat("1st stage F stat", e(widstat))	

	local t1=_b[l.it12_all]/_se[l.it12_all]
	if abs(`t1')<=1.645 local stars=""
	if abs(`t1')>1.645 local stars="*"
	if abs(`t1')>1.960 local stars="**"
	if abs(`t1')>2.326 local stars="***"
	
	local v_coef=string(_b[l.it12_all],"%4.3f")+"`stars'"
	local v_se  ="(" + string(_se[l.it12_all],"%4.3f")+")"
	local v_R2  =string(e(r2c),"%5.3f")
	local v_F1  = string(e(widstat),"%5.2f")
	local v_N  = string(e(N),"%8.0gc")
	
post `tempfile0' ("Please indicate direction and intensity of the following FACTORS as they will affect your firm’s selling prices in the next 12 months: (scale from -3 to 3): PRICING POLICIES of your firm’s main competitors") ("`v_coef'") ("`v_R2'") ("`v_F1'") ("`v_N'")
post `tempfile0' (" ") ("`v_se'") (" ") (" ") (" ")	

postclose `tempfile0'


	
	
	